using System;
using System.Collections.Generic;
using Unity.Mathematics;
using UnityEngine;

namespace GpuHud
{
    public static class GpuHudUtils
    {
        private static Dictionary<GpuHudStyle, Type> m_TypeMap = new Dictionary<GpuHudStyle, Type>();

        static GpuHudUtils()
        {
            m_TypeMap.Add(GpuHudStyle.Image, typeof(GpuHudImageStyleAccessor));
            m_TypeMap.Add(GpuHudStyle.Text, typeof(GpuHudTextStyleAccessor));
            m_TypeMap.Add(GpuHudStyle.HealthBar, typeof(GpuHudHealthBarAccessor));
        }
        
        public enum GpuHudStyle
        {
            Image,
            Text,
            HealthBar,
        }

        public static Type GetAccessorType(GpuHudStyle style)
        {
            return m_TypeMap.ContainsKey(style) ? m_TypeMap[style] : null;
        }
        
        public static float4 GetUVRect(Sprite sprite)
        {
            if (sprite == null)
                return default;
            var texture = sprite.texture;
            var rect = sprite.textureRect;
            return new float4(rect.x/texture.width, rect.y/texture.height, rect.width/texture.width, rect.height/texture.height);
        }

    }
}